<template>
	<view class="address" @click="chooseAddress">
		<image class="icon" src="/static/images/adderss1.png" mode=""></image>
		<view class="txtbox" v-if="!!address.id">
			<view class="title ellipsis">
				{{ address.province + address.city + address.district + address.address }}
			</view>
			<view class="userBox">
				<view class="name">
					{{ address.contact }}
				</view>
				<view class="num">
					{{ address.telephone }}
				</view>
			</view>
		</view>
		<view class="txtbox" v-else>请选择地址</view>
		<image src="/static/navTo.png" class="navto" mode=""></image>
	</view>
</template>

<script>
	export default {
		name: 'chooseAddress',

		data() {
			return {
				address: {},
			};
		},
		created() {
			uni.$on('chooseAddress', (e) => {
				this.address = e;
				this.$emit('addressChange', e.id);
			});
			this.init();
		},
		methods: {
			chooseAddress() {
				uni.navigateTo({
					url: '/pages/my/address/address?type=0',
				});
			},
			async init() {
				const { data } = await this.$api.getDefaultAddress();
				this.address = data;
				this.$emit('addressChange', data.id);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.address {
		margin: $margin-width auto;
		background-color: $price-color;
		width: $connet-width;
		height: 160rpx;
		background: #d9220a;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		align-items: center;
		color: $txt-color;
		justify-content: space-around;

		.icon {
			width: 46rpx;
			height: 50rpx;
			margin-left: $margin-width;
		}

		.txtbox {
			height: 100%;
			margin-left: $margin-width;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			width: 500rpx;

			.title {
				font-size: $uni-font-size-15;
				font-weight: bold;
			}

			.userBox {
				display: flex;
				font-size: $uni-font-size-14;

				.name {
					margin-right: $margin-width;
				}
			}
		}

		.navto {
			margin-right: 30rpx;
			width: 50rpx;
			height: 50rpx;
		}
	}
</style>
